package com.one.consumer.reserve.ui.activity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.view.base.IListView;
import com.one.common.view.widget.MyTitleBar;
import com.one.consumer.BaseListActivityC;
import com.one.consumer.reserve.model.extra.CaseExtra;
import com.one.common.common.order.extra.ReserveExtra;
import com.one.consumer.reserve.model.item.CaseItem;
import com.one.consumer.reserve.model.item.ProgramItem;
import com.one.consumer.reserve.model.item.ProjectTypeItem;
import com.one.consumer.reserve.presenter.DECaseListPresenter;
import com.one.consumer.reserve.ui.binder.CaseBinder;
import com.one.consumer.reserve.ui.binder.ProgramBinder;
import com.one.consumer.reserve.ui.binder.ProjectTypeBinder;

/**
 * author ：zhulunjun
 * email  ：zhulunjun@qq.com
 * date   ：2018/10/21 下午8:07
 * description ：装修案例
 **/
@Route(path = RouterPath.CASE_LIST)
public class DecorationCaseActivity extends BaseListActivityC<DECaseListPresenter> implements IListView,
        CaseBinder.OnCaseClick, ProgramBinder.OnProgramClick,
        ProjectTypeBinder.OnProjectTypeClick {
    private ReserveExtra extra;

    @Override
    protected void initPresenter() {
        mPresenter = new DECaseListPresenter(this, this);
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        extra = (ReserveExtra) getIntent().getSerializableExtra(ReserveExtra.getExtraName());
        String title;
        if (extra.getType().equals(ReserveExtra.STYLE_CU)) {
            title = "户型选择";
        } else if (extra.getType().equals(ReserveExtra.STYLE_PR)) {
            title = "方案选择";
        } else {
            title = "案例展示";
        }
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                .setTitleText(title);

    }

    @Override
    public void registerDate() {
        register(CaseItem.class, new CaseBinder(this));
        register(ProgramItem.class, new ProgramBinder(this));
        register(ProjectTypeItem.class, new ProjectTypeBinder(this));
    }

    @Override
    public void loadData() {
        if (extra.getType().equals(ReserveExtra.STYLE_CU)) {
            mPresenter.getProjectTypeList(extra.getId());
        } else if (extra.getType().equals(ReserveExtra.STYLE_PR)) {
            mPresenter.getProjectProgramList(extra.getId());
        } else {
            mPresenter.getCaseListDE();
        }

    }

    @Override
    public void initView() {
        super.initView();
        if (extra.getType().equals(ReserveExtra.STYLE_CU) ||
                extra.getType().equals(ReserveExtra.STYLE_PR)) {
            hindLoadMore();
        }
    }

    @Override
    public void initData() {
        super.initData();
        loadData();
    }

    /**
     * 装修方案选择
     */
    @Override
    public void caseClick(CaseItem item) {
        RouterManager.getInstance().go(RouterPath.CASE_DETAIL,
                new CaseExtra(item.getEffect_id() + "",
                        item.getEffect_name(), extra.getType()));
    }

    /**
     * 户型选择
     */
    @Override
    public void typeClick(ProjectTypeItem item) {
        ReserveExtra reserveExtra = new ReserveExtra(ReserveExtra.STYLE_PR, item.getHuxing_id() + "");
        reserveExtra.setCustomExtra(extra.getCustomExtra());
        reserveExtra.getCustomExtra().setTypeId(item.getHuxing_id() + "");
        reserveExtra.getCustomExtra().setTypeName(item.getHuxing_name());
        RouterManager.getInstance().go(RouterPath.CASE_LIST, reserveExtra);
    }

    /**
     * 户型方案选择
     */
    @Override
    public void programClick(ProgramItem item) {
        extra.getCustomExtra().setProgramId(item.getProgramme_id() + "");
        extra.getCustomExtra().setProgramName(item.getProgramme_name());
        extra.getCustomExtra().setPrice(item.getProgramme_price());
        RouterManager.getInstance().go(RouterPath.CASE_DETAIL,
                new CaseExtra(item.getHuxing_id() + "",
                        item.getProgramme_name(),
                        item.getProgramme_id()+"",
                        extra.getType(),
                        item.getProgramme_imgs(),
                        extra.getCustomExtra()));
    }
}
